<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <!-- 功能实现：动态的给student添加sex属性，而且属性能被vm监听到 -->
    <div id="root">
        <h1>{{student.name}}</h1>
        <h1>{{student.age}}</h1>
        <!-- 如果{{}}里面是undefined则不会显示，也不会报错 -->
        <!-- <h1>{{undefined}}</h1> -->
        <h1>{{student.sex}}</h1>
        <button @click="addSex">添加性别属性</button>
    </div>
    <script>
        Vue.config.productionTip = false;
        let vm = new Vue({
            el:'#root',
            data:{
                name:'尚硅谷',
                student:{
                    name:'张三',
                    age:23
                }
            },
            methods: {
                addSex(){
                    // 给vue.student对象添加sex属性，属性值为男
                    // Vue.set(this.student, 'sex', "男");
                    // 另一种写法
                    this.$set(this.student, "sex", "女");
                }
            },
        });
    </script>
</body>
</html>